/*
 * Audible.h
 *
 *  Created on: 2009/02/01
 *      Author: Yongshik Cho
 */

#ifndef AUDIBLE_H_
#define AUDIBLE_H_

#include "../core/ISmartPtr.h"
#include "../core/Vector2D.h"
#include "../Sound.h"

#ifndef EVENTDISPATCHER_H_
#	include "../EventDispatcher.h"
#endif

class Audible : public ISmartPtr<Audible>,  public EventDispatcher
{
public:
	enum LOOP_TYPE
	{
		LOOP_COUNT,
		ENDLESS
	};

	static const uint32	_BUFFER_COUNT 			= 4;

public:
	Audible(Sound* sound = 0);
	virtual ~Audible();

	virtual void prePlayback();
	virtual void playback();
	virtual void postPlayback();

	inline const String& getName() const { return mName; }
	inline void setName(const String& name) { mName = name; }

	inline const Vector2D& getPosition() const { return mPosition; }
	inline void setPosition(const Vector2D& position) { mPosition = position; }
	inline const Vector2D& getVelocity() const { return mVelocity; }
	inline void setVelocity(const Vector2D& velocity) { mVelocity = velocity; }
	inline const Vector2D& getDirection() const { return mDirection; }
	inline void setDirection(const Vector2D& direction) { mDirection = direction; }
	inline const float getRolloff() const { return mRolloff; }
	inline void setRolloff(const float rolloff) { mRolloff = rolloff; }

	inline Sound* getSound() { return mSound; }
	inline void setSound(Sound* sound) { mSound = sound; }

	inline const bool getAudible() const { return mAudible; }
	inline void setAudible(const bool audible) { mAudible = audible; }

	inline uint8 getLoopType() const { return mLoopType; }
	inline void setLoopType(const uint8 type) { mLoopType = type; }
	inline uint32& getLoopCount() { return mLoopCount; }
	inline void setLoopCount(const uint32 count) { mLoopCount = count; }

	inline const bool getQueued() const { return mQueued; }
	inline void setQueued(const bool queued) { mQueued = queued; }
	inline const uint32 getBufferedCount()
	{
		if(!mSound)
			return 0;

		return mSound->getQueueCount();
	}

protected:
	String		mName;
	Vector2D 	mPosition;
	Vector2D	mVelocity;
	Vector2D	mDirection;
	float		mRolloff;
	Sound*		mSound;
	bool		mAudible;
	uint8		mLoopType;
	uint32		mLoopCount;
	bool		mQueued;
	uint32		mBufferedCount;
};

#endif /* AUDIBLE_H_ */
